package com.boot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.boot.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select role from sys_users u, sys_roles r,sys_users_roles ur where u.username=#{username} and u.id=ur.user_id and r.id=ur.role_id")
    Set<String> findRoles(@Param("username") String username);

    @Select("select permission from sys_users u, sys_roles r, sys_permissions p, sys_users_roles ur, sys_roles_permissions rp where u.username=#{username} and u.id=ur.user_id and r.id=ur.role_id and r.id=rp.role_id and p.id=rp.permission_id")
    Set<String> findPermissions(@Param("username") String username);
}
